﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;

namespace YJKGridTopologyCal.Geometries.Utilities
{
	public class PointExtracter : IGeometryFilter
	{
		public static ICollection<IGeometry> GetPoints(IGeometry geom, List<IGeometry> list)
		{
			if (geom is IPoint)
			{
				list.Add(geom);
			}
			else if (geom is IGeometryCollection)
			{
				geom.Apply(new PointExtracter(list));
			}
			return list;
		}

		public static ICollection<IGeometry> GetPoints(IGeometry geom)
		{
			return PointExtracter.GetPoints(geom, new List<IGeometry>());
		}

		public PointExtracter(List<IGeometry> pts)
		{
			this._pts = pts;
		}

		public void Filter(IGeometry geom)
		{
			if (geom is IPoint)
			{
				this._pts.Add(geom);
			}
		}

		private readonly List<IGeometry> _pts;
	}
}
